/*
 * Servidor.java
 *
 * Created on 16-nov-2011, 22:48:16
 */
package edu.uoc.tdp.server;

import edu.uoc.tdp.i18n.TDPLanguageUtils;
import edu.uoc.tdp.i18n.TDPLanguageConstants;
import java.util.Locale;

/**
 *
 * @author tomeu
 */
public class Servidor extends javax.swing.JFrame {

    public Server server;

    /** Creates new form Servidor */
    public Servidor() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        btnStartServer = new javax.swing.JButton();
        btnStopServer = new javax.swing.JButton();
        lblMsg = new javax.swing.JLabel();

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(480, 76));
        setName(""); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        btnStartServer.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnStartServer.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.SERVER_START));
        btnStartServer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnStartServerMousePressed(evt);
            }
        });

        btnStopServer.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnStopServer.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.SERVER_STOP));
        btnStopServer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnStopServerMousePressed(evt);
            }
        });

        lblMsg.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblMsg.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.SERVER_INFORMATION));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblMsg, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnStartServer, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnStopServer, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblMsg)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnStartServer, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(btnStopServer, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnStartServerMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnStartServerMousePressed

    this.lblMsg.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.SERVER_INFORMATION_REFRESH));

    btnStartServer.setEnabled(false);
    btnStopServer.setEnabled(true);
    server = new Server();
}//GEN-LAST:event_btnStartServerMousePressed

private void btnStopServerMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnStopServerMousePressed
    btnStartServer.setEnabled(true);
    btnStopServer.setEnabled(false);
    server.finalize();

}//GEN-LAST:event_btnStopServerMousePressed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    server.finalize();
    dispose();
    System.exit(0);
}//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        initialitzeApplication(args);
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Servidor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Servidor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Servidor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Servidor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Servidor().setVisible(true);
            }
        });
    }

    private static void initialitzeApplication(String[] args) {
        if (args.length == 0) {
            TDPLanguageUtils.setDefaultLanguage("i18n/messages");
        } else if (args.length == 1) {
            Locale locale = new Locale(args[0]);
            TDPLanguageUtils.setLanguage("i18n/messages", locale);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnStartServer;
    private javax.swing.JButton btnStopServer;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel lblMsg;
    // End of variables declaration//GEN-END:variables
}
